rename(InflationRisk_basedate = InflationRisk)
US_Moments_Final20 <- left_join(US_Moments_Final20, base, by=c("event_id"="event_id"))
US_Moments_Final20 <- US_Moments_Final20 %>%
group_by(event_id) %>%
mutate(delta_inflation = InflationRisk - InflationRisk_basedate)
#Collapse data
final_data <- US_Moments_Final20 %>%
#filter(event_id <= 10) %>%
group_by(event_window) %>%
summarise(mean_delta_inflation = mean(delta_inflation, na.rm = T),
sd_delta_inflation = sd(delta_inflation, na.rm = T),
count = n_distinct(event_id))
#Add Confidence Interval
final_data <- final_data %>%
mutate(upper = mean_delta_inflation + 1.96*(sd_delta_inflation/sqrt(22)),
lower = mean_delta_inflation - 1.96*(sd_delta_inflation/sqrt(22)))
#Add CI
fig <- ggplot(data = final_data)+
geom_line(aes(x=event_window, y=mean_delta_inflation)) +
theme_bw()+
ggtitle("20yr inflation expectations around CBO announcements" ,subtitle = "Change from t=0")+
ylab("Change in % (Prob inflation is >4%)")+
xlab("Event Time (Days)") +
geom_hline(yintercept = 0, linetype="dotted",
color = "blue", size=1) +
ylim(-1, 2)
fig <- fig + geom_ribbon(aes(x=event_window, y=mean_delta_inflation, ymin = lower, ymax = upper), alpha=0.1, fill = "red")
fig
pdf("_Output/plot_event_20yr.pdf")
fig
dev.off()
#Add CI
fig <- ggplot(data = final_data)+
geom_line(aes(x=event_window, y=mean_delta_inflation)) +
theme_bw()+
ggtitle("20yr inflation expectations around CBO announcements" ,subtitle = "Change from t=0")+
ylab("Change in % (Prob inflation is >4%)")+
xlab("Event Time (Days)") +
geom_hline(yintercept = 0, linetype="dotted",
color = "blue", size=1) +
ylim(-1, 1)
fig <- fig + geom_ribbon(aes(x=event_window, y=mean_delta_inflation, ymin = lower, ymax = upper), alpha=0.1, fill = "red")
fig
pdf("_Output/plot_event_20yr.pdf")
fig
dev.off()
#Clear user defined environment
rm(list=ls())
#Load packages
install.packages("pacman")
library(pacman)
p_load(readxl, lubridate, dplyr, tidyverse, data.table, lubridate, quantmod, haven, FinancialMath, jrvFinance)
#options
options(digits=4)
options(stringsAsFactors = FALSE)
options(scipen=999)
#Assign dplyr verbs
select <- select
rename <- rename
mutate <- mutate
filter <- filter
arrange <- arrange
distinct <- distinct
group_by <- group_by
summarise <- summarise
#Functionsefine directories
global <- "C:/Users/asp.fi/Dropbox (CBS)/2019_Gilchrist and Zakrajsek/02 R Scripts/2024_RFS_Replication_TOZIP"
US_Moments_Final5 <- read_csv("C:/Users/asp.fi/Dropbox (Personal)/1. Projects/2024_Treasury Refunding Announcements and Inflation/Data/Implied Inflation (Sebastian)/US Moments.Final5.csv",
col_types = cols(date = col_date(format = "%Y-%m-%d")))
US_Moments_Final15 <- read_csv("C:/Users/asp.fi/Dropbox (Personal)/1. Projects/2024_Treasury Refunding Announcements and Inflation/Data/Implied Inflation (Sebastian)/US Moments.Final15.csv",
install.packages("pacman")
col_types = cols(date = col_date(format = "%Y-%m-%d")))
#Clear user defined environment
rm(list=ls())
#Load packages
install.packages("pacman")
library(pacman)
p_load(readxl, lubridate, dplyr, tidyverse, data.table, lubridate, quantmod, haven, FinancialMath, jrvFinance)
#options
options(digits=4)
options(stringsAsFactors = FALSE)
options(scipen=999)
#Assign dplyr verbs
select <- select
rename <- rename
mutate <- mutate
filter <- filter
arrange <- arrange
distinct <- distinct
group_by <- group_by
summarise <- summarise
#Functionsefine directories
global <- "C:/Users/asp.fi/Dropbox (CBS)/2019_Gilchrist and Zakrajsek/02 R Scripts/2024_RFS_Replication_TOZIP"
US_Moments_Final5 <- read_csv("C:/Users/asp.fi/Dropbox (Personal)/1. Projects/2024_Treasury Refunding Announcements and Inflation/Data/Implied Inflation (Sebastian)/US Moments.Final5.csv",
col_types = cols(date = col_date(format = "%Y-%m-%d")))
US_Moments_Final15 <- read_csv("C:/Users/asp.fi/Dropbox (Personal)/1. Projects/2024_Treasury Refunding Announcements and Inflation/Data/Implied Inflation (Sebastian)/US Moments.Final15.csv",
col_types = cols(date = col_date(format = "%Y-%m-%d")))
US_Moments_Final20 <- read_csv("C:/Users/asp.fi/Dropbox (Personal)/1. Projects/2024_Treasury Refunding Announcements and Inflation/Data/Implied Inflation (Sebastian)/US Moments.Final20.csv",
col_types = cols(date = col_date(format = "%Y-%m-%d")))
US_Moments_Final5 <- US_Moments_Final5 %>%
mutate(InflationRisk = InflationRisk*100)
US_Moments_Final15 <- US_Moments_Final15 %>%
mutate(InflationRisk = InflationRisk*100)
US_Moments_Final20 <- US_Moments_Final20 %>%
mutate(InflationRisk = InflationRisk*100)
dates <- read_excel("C:/Users/asp.fi/Dropbox (Personal)/1. Projects/2024_Treasury Refunding Announcements and Inflation/Data/CBO_Processed/cbo_total_defecit.xlsx",
sheet = "dates", col_types = c("date"))
dates <- dates %>%
mutate(event_id = row_number()) %>%
mutate(cbo = 0)
US_Moments_Final5 <- left_join(US_Moments_Final5, dates, by=c("date"="dates"))
#Add event window
for (i in c(seq(from = 1, to = 30))){
new_col_name <- paste0("dv_plus_",i,sep="")
US_Moments_Final5 <- US_Moments_Final5 %>%
mutate(!!sym(new_col_name) := dplyr::lag(cbo, n=i) + i)
}
for (i in c(seq(from = 1, to = 30))){
new_col_name <- paste0("dv_minus_",i,sep="")
US_Moments_Final5 <- US_Moments_Final5 %>%
mutate(!!sym(new_col_name) := dplyr::lead(cbo, n=i) - i)
}
#Keep only event window prices
US_Moments_Final5 <- US_Moments_Final5 %>%
mutate(event_window = coalesce(dv_minus_30,
dv_minus_29,
dv_minus_28,
dv_minus_27,
dv_minus_26,
dv_minus_25,
dv_minus_24,
dv_minus_23,
dv_minus_22,
dv_minus_21,
dv_minus_20,
dv_minus_19,
dv_minus_18,
dv_minus_17,
dv_minus_16,
dv_minus_15,
dv_minus_14,
dv_minus_13,
dv_minus_12,
dv_minus_11,
dv_minus_10,
dv_minus_9,
dv_minus_8,
dv_minus_7,
dv_minus_6,
dv_minus_5,
dv_minus_4,
dv_minus_3,
dv_minus_2,
dv_minus_1,
cbo,
dv_plus_1,
dv_plus_2,
dv_plus_3,
dv_plus_4,
dv_plus_5,
dv_plus_6,
dv_plus_7,
dv_plus_8,
dv_plus_9,
dv_plus_10,
dv_plus_11,
dv_plus_12,
dv_plus_13,
dv_plus_14,
dv_plus_15,
dv_plus_16,
dv_plus_17,
dv_plus_18,
dv_plus_19,
dv_plus_20,
dv_plus_21,
dv_plus_22,
dv_plus_23,
dv_plus_24,
dv_plus_25,
dv_plus_26,
dv_plus_27,
dv_plus_28,
dv_plus_29,
dv_plus_30)) %>%
select(date, event_id, InflationRisk, cbo, event_window) %>%
filter(!is.na(event_window))
for (i in c(seq(from = 1, to = 30))){
new_col_name <- paste0("event_id_plus_",i,sep="")
US_Moments_Final5 <- US_Moments_Final5 %>%
mutate(!!sym(new_col_name) := dplyr::lag(event_id, n=i))
}
for (i in c(seq(from = 1, to = 30))){
new_col_name <- paste0("event_id_minus_",i,sep="")
US_Moments_Final5 <- US_Moments_Final5 %>%
mutate(!!sym(new_col_name) := dplyr::lead(event_id, n=i))
}
#Keep only event window prices
US_Moments_Final5 <- US_Moments_Final5 %>%
mutate(event_id = coalesce(event_id_minus_30,
event_id_minus_29,
event_id_minus_28,
event_id_minus_27,
event_id_minus_26,
event_id_minus_25,
event_id_minus_24,
event_id_minus_23,
event_id_minus_22,
event_id_minus_21,
event_id_minus_20,
event_id_minus_19,
event_id_minus_18,
event_id_minus_17,
event_id_minus_16,
event_id_minus_15,
event_id_minus_14,
event_id_minus_13,
event_id_minus_12,
event_id_minus_11,
event_id_minus_10,
event_id_minus_9,
event_id_minus_8,
event_id_minus_7,
event_id_minus_6,
event_id_minus_5,
event_id_minus_4,
event_id_minus_3,
event_id_minus_2,
event_id_minus_1,
event_id,
event_id_plus_1,
event_id_plus_2,
event_id_plus_3,
event_id_plus_4,
event_id_plus_5,
event_id_plus_6,
event_id_plus_7,
event_id_plus_8,
event_id_plus_9,
event_id_plus_10,
event_id_plus_11,
event_id_plus_12,
event_id_plus_13,
event_id_plus_14,
event_id_plus_15,
event_id_plus_16,
event_id_plus_17,
event_id_plus_18,
event_id_plus_19,
event_id_plus_20,
event_id_plus_21,
event_id_plus_22,
event_id_plus_23,
event_id_plus_24,
event_id_plus_25,
event_id_plus_26,
event_id_plus_27,
event_id_plus_28,
event_id_plus_29,
event_id_plus_30)) %>%
select(date, event_id, InflationRisk, cbo, event_window) %>%
filter(!is.na(event_window))
base <- US_Moments_Final5 %>%
na.omit() %>%
select(event_id, InflationRisk) %>%
rename(InflationRisk_basedate = InflationRisk)
US_Moments_Final5 <- left_join(US_Moments_Final5, base, by=c("event_id"="event_id"))
US_Moments_Final5 <- US_Moments_Final5 %>%
group_by(event_id) %>%
mutate(delta_inflation = InflationRisk - InflationRisk_basedate)
#Collapse data
final_data <- US_Moments_Final5 %>%
#filter(event_id <= 10) %>%
group_by(event_window) %>%
summarise(mean_delta_inflation = mean(delta_inflation, na.rm = T),
sd_delta_inflation = sd(delta_inflation, na.rm = T),
count = n_distinct(event_id))
#Add Confidence Interval
final_data <- final_data %>%
mutate(upper = mean_delta_inflation + 1.96*(sd_delta_inflation/sqrt(22)),
lower = mean_delta_inflation - 1.96*(sd_delta_inflation/sqrt(22)))
#Add CI
fig <- ggplot(data = final_data)+
geom_line(aes(x=event_window, y=mean_delta_inflation)) +
theme_bw()+
ggtitle("5yr inflation expectations around CBO announcements" ,subtitle = "Change from t=0")+
ylab("Change in % (Prob inflation is >4%)")+
xlab("Event Time (Days)") +
geom_hline(yintercept = 0, linetype="dotted",
color = "blue", size=1) +
ylim(-1, 2)
fig <- fig + geom_ribbon(aes(x=event_window, y=mean_delta_inflation, ymin = lower, ymax = upper), alpha=0.1, fill = "red")
fig
pdf("_Output/plot_event_5yr.pdf")
fig
dev.off()
fig <- ggplot(data = final_data)+
geom_line(aes(x=event_window, y=mean_delta_inflation)) +
theme_bw()+
ggtitle("5yr inflation expectations around CBO announcements" ,subtitle = "Change from t=0")+
ylab("Change in % (Prob inflation is >4%)")+
xlab("Event Time (Days)") +
geom_hline(yintercept = 0, linetype="dotted",
color = "blue", size=1) +
ylim(-1, 2)
fig <- fig + geom_ribbon(aes(x=event_window, y=mean_delta_inflation, ymin = lower, ymax = upper), alpha=0.1, fill = "red")
fig
#Add CI
fig <- ggplot(data = final_data)+
geom_line(aes(x=event_window, y=mean_delta_inflation)) +
theme_bw()+
ggtitle("5yr inflation expectations around CBO announcements" ,subtitle = "Change from t=0")+
ylab("Change in % (Prob inflation is >4%)")+
xlab("Event Time (Days)") +
geom_hline(yintercept = 0, linetype="dotted",
color = "blue", size=1) +
ylim(-2, 2)
fig <- fig + geom_ribbon(aes(x=event_window, y=mean_delta_inflation, ymin = lower, ymax = upper), alpha=0.1, fill = "red")
fig
View(fig)
View(final_data)
dates <- read_excel("C:/Users/asp.fi/Dropbox (Personal)/1. Projects/2024_Treasury Refunding Announcements and Inflation/Data/CBO_Processed/cbo_total_defecit.xlsx",
sheet = "dates", col_types = c("date"))
dates <- dates %>%
mutate(event_id = row_number()) %>%
mutate(cbo = 0)
US_Moments_Final15 <- left_join(US_Moments_Final15, dates, by=c("date"="dates"))
#Add event window
for (i in c(seq(from = 1, to = 30))){
new_col_name <- paste0("dv_plus_",i,sep="")
US_Moments_Final15 <- US_Moments_Final15 %>%
mutate(!!sym(new_col_name) := dplyr::lag(cbo, n=i) + i)
}
for (i in c(seq(from = 1, to = 30))){
new_col_name <- paste0("dv_minus_",i,sep="")
US_Moments_Final15 <- US_Moments_Final15 %>%
mutate(!!sym(new_col_name) := dplyr::lead(cbo, n=i) - i)
}
#Keep only event window prices
US_Moments_Final15 <- US_Moments_Final15 %>%
mutate(event_window = coalesce(dv_minus_30,
dv_minus_29,
dv_minus_28,
dv_minus_27,
dv_minus_26,
dv_minus_25,
dv_minus_24,
dv_minus_23,
dv_minus_22,
dv_minus_21,
dv_minus_20,
dv_minus_19,
dv_minus_18,
dv_minus_17,
dv_minus_16,
dv_minus_15,
dv_minus_14,
dv_minus_13,
dv_minus_12,
dv_minus_11,
dv_minus_10,
dv_minus_9,
dv_minus_8,
dv_minus_7,
dv_minus_6,
dv_minus_5,
dv_minus_4,
dv_minus_3,
dv_minus_2,
dv_minus_1,
cbo,
dv_plus_1,
dv_plus_2,
dv_plus_3,
dv_plus_4,
dv_plus_5,
dv_plus_6,
dv_plus_7,
dv_plus_8,
dv_plus_9,
dv_plus_10,
dv_plus_11,
dv_plus_12,
dv_plus_13,
dv_plus_14,
dv_plus_15,
dv_plus_16,
dv_plus_17,
dv_plus_18,
dv_plus_19,
dv_plus_20,
dv_plus_21,
dv_plus_22,
dv_plus_23,
dv_plus_24,
dv_plus_25,
dv_plus_26,
dv_plus_27,
dv_plus_28,
dv_plus_29,
dv_plus_30)) %>%
select(date, event_id, InflationRisk, cbo, event_window) %>%
filter(!is.na(event_window))
for (i in c(seq(from = 1, to = 30))){
new_col_name <- paste0("event_id_plus_",i,sep="")
US_Moments_Final15 <- US_Moments_Final15 %>%
mutate(!!sym(new_col_name) := dplyr::lag(event_id, n=i))
}
for (i in c(seq(from = 1, to = 30))){
new_col_name <- paste0("event_id_minus_",i,sep="")
US_Moments_Final15 <- US_Moments_Final15 %>%
mutate(!!sym(new_col_name) := dplyr::lead(event_id, n=i))
}
#Keep only event window prices
US_Moments_Final15 <- US_Moments_Final15 %>%
mutate(event_id = coalesce(event_id_minus_30,
event_id_minus_29,
event_id_minus_28,
event_id_minus_27,
event_id_minus_26,
event_id_minus_25,
event_id_minus_24,
event_id_minus_23,
event_id_minus_22,
event_id_minus_21,
event_id_minus_20,
event_id_minus_19,
event_id_minus_18,
event_id_minus_17,
event_id_minus_16,
event_id_minus_15,
event_id_minus_14,
event_id_minus_13,
event_id_minus_12,
event_id_minus_11,
event_id_minus_10,
event_id_minus_9,
event_id_minus_8,
event_id_minus_7,
event_id_minus_6,
event_id_minus_5,
event_id_minus_4,
event_id_minus_3,
event_id_minus_2,
event_id_minus_1,
event_id,
event_id_plus_1,
event_id_plus_2,
event_id_plus_3,
event_id_plus_4,
event_id_plus_5,
event_id_plus_6,
event_id_plus_7,
event_id_plus_8,
event_id_plus_9,
event_id_plus_10,
event_id_plus_11,
event_id_plus_12,
event_id_plus_13,
event_id_plus_14,
event_id_plus_15,
event_id_plus_16,
event_id_plus_17,
event_id_plus_18,
event_id_plus_19,
event_id_plus_20,
event_id_plus_21,
event_id_plus_22,
event_id_plus_23,
event_id_plus_24,
event_id_plus_25,
event_id_plus_26,
event_id_plus_27,
event_id_plus_28,
event_id_plus_29,
event_id_plus_30)) %>%
select(date, event_id, InflationRisk, cbo, event_window) %>%
filter(!is.na(event_window))
base <- US_Moments_Final15 %>%
na.omit() %>%
select(event_id, InflationRisk) %>%
rename(InflationRisk_basedate = InflationRisk)
US_Moments_Final15 <- left_join(US_Moments_Final15, base, by=c("event_id"="event_id"))
US_Moments_Final15 <- US_Moments_Final15 %>%
group_by(event_id) %>%
mutate(delta_inflation = InflationRisk - InflationRisk_basedate)
#Collapse data
final_data <- US_Moments_Final15 %>%
#filter(event_id <= 10) %>%
group_by(event_window) %>%
summarise(mean_delta_inflation = mean(delta_inflation, na.rm = T),
sd_delta_inflation = sd(delta_inflation, na.rm = T),
count = n_distinct(event_id))
#Add Confidence Interval
final_data <- final_data %>%
mutate(upper = mean_delta_inflation + 1.96*(sd_delta_inflation/sqrt(22)),
lower = mean_delta_inflation - 1.96*(sd_delta_inflation/sqrt(22)))
#Add CI
fig <- ggplot(data = final_data)+
geom_line(aes(x=event_window, y=mean_delta_inflation)) +
theme_bw()+
ggtitle("15yr inflation expectations around CBO announcements" ,subtitle = "Change from t=0")+
ylab("Change in % (Prob inflation is >4%)")+
xlab("Event Time (Days)") +
geom_hline(yintercept = 0, linetype="dotted",
color = "blue", size=1) +
ylim(-0.5, 1)
fig <- fig + geom_ribbon(aes(x=event_window, y=mean_delta_inflation, ymin = lower, ymax = upper), alpha=0.1, fill = "red")
fig
pdf("_Output/plot_event_15yr.pdf")
fig
dev.off()
